package com.dhy.config;

import com.dhy.util.YamlUtil;

import static com.dhy.util.AssertUtil.NOT_NULL;

/**
 * @author 大忽悠
 * @create 2022/5/29 20:35
 */
public class ClientConfig {
    private YamlUtil yamlUtil;
    private static final String DEFAULT_CONFIG_PATH="redis.yaml";
    private static final String TOP_LEVEL="redis.";
    private  final String host;
    private  final Integer port;
    private  final String password;
    private  final Boolean NEED_AUTH;

    public ClientConfig() {
        this.yamlUtil=new YamlUtil(DEFAULT_CONFIG_PATH);
        this.host=yamlUtil.get(TOP_LEVEL+"host");
        this.port= Integer.valueOf(yamlUtil.get(TOP_LEVEL+"port"));
        this.password=yamlUtil.get(TOP_LEVEL+"password");
        this.NEED_AUTH=  password != null;
        NOT_NULL(host,port);
    }

    public ClientConfig(String configPath) {
        this.yamlUtil=new YamlUtil(configPath);
        this.host=yamlUtil.get(TOP_LEVEL+"host");
        this.port= Integer.valueOf(yamlUtil.get(TOP_LEVEL+"port"));
        this.password=yamlUtil.get(TOP_LEVEL+"password");
        this.NEED_AUTH= password != null;
        NOT_NULL(host,port);
    }

    public String getHost() {
        return host;
    }

    public Integer getPort() {
        return port;
    }

    public String getPassword() {
        return password;
    }

    public Boolean getNEED_AUTH() {
        return NEED_AUTH;
    }
}
